/**
 * 快速打印页面 js
 * @author [song cheng lin]
 */


  $(function(){
  	//获取出院科室
  	$("#FastPrint_Dept").combobox({
  		url:ctx + "/Print/getDept",
  		valueField:"ftykh",
  		textField:"fksname",
  		width:120, 
  		height:24,
  		queryParams :{
  			"fcode" : sysFcode
  		},
  		onLoadSuccess : function() {
  			$('#FastPrint_Dept').combobox('select', 'TZYQY');
  		},
  		onSelect : function(record){
  			var code = record.ftykh;
  			loadCybs(code);
  		}
  	});
  	
  	//获取主治医生
  	$("#FastPrint_fzydoc").combobox({
  		url:ctx + "/Print/getZzDoc",
  		valueField:"fzzdoctbh",
  		textField:"fzzdoct",
  		width:120, 
  		height:24
  	});

  		//加载数据表格
  		$("#FastPrintGrid").datagrid({
  			url:'',
  			toolbar:"#FastPrintBar",
  			fitColumns:true,
  			border : false,
  			striped : true,
  			fit : true,
  			singleSelect: true,
  			pagination : true,
  			pageSize : 20,
  			pageList : [ 20, 30,50 ],
  			columns:[[
				{field:'FID',title:'ID',width:0,align:'center',hidden:true},	
  	            {field:'operat',title:'操作',width:60,align:'center',
  	            	formatter:function(value,row,index){
  	            		return "<button class='shootBtn' onclick='openRegister("+index+")'>打印</button>";
  	            	}
  	            }, 
  	            {field:'ftpzz',title:'图片制作',width:100,align:'center' },
  	            {field:'fszgd',title:'数字归档',width:100,align:'center' },  
  				{field:'location',title:'当前位置',width:100,align:'center'},  
  				{field:'fname',title:'患者姓名',width:90,align:'center' },
  				{field:'fprn',title:'病案号',width:130,align:'center'},
  				{field:'fcydate',title:'出院日期',width:130,align:'center',
  					formatter:function(value){
  						return new Date(value).format("yyyy-MM-dd");
  					}
  				}, 
  				{field:'fsex',title:'性别',width:60,align:'center' }, 
  				{field:'fage',title:'年龄',width:60,align:'center' }, 
  				{field:'fcydept',title:'出院科室',width:130,align:'center' },
  				{field:'fcydept',title:'出院病区',width:130,align:'center' },
  				{field:'fzzdoct',title:'主治医生',width:130,align:'center' },   				
  				{field:'ftimes',title:'次数',width:60,align:'center' },  
  				{field:'fidcard',title:'身份证号',width:130,align:'center',hidden:true }, 
  				{field:'frydate',title:'入院日期',width:130,align:'center',
  					formatter:function(value){
  						return new Date(value).format("yyyy-MM-dd");
  					}	
  				} ,  
  				{field:'fbarcode',title:'条码号',width:180,align:'center' }   				
  			       ]]
  		});
  	});

  	//获取出院病区
  		function loadCybs(code){
  			var ksbh = "";
  			if(code != "" && code != null){
  				ksbh = code;
  			}
  			$("#FastPrint_fcybq").combobox({
  				url:ctx + "/Print/getFcybs",
  				valueField:"fhiskh",
  				textField:"fhisksname",
  				width:120, 
  				height:24,
  				queryParams : {
  					'ksbh' : ksbh,
  					"fcode" : sysFcode
  				},
  				onLoadSuccess : function(){
  					if(sysFbqdm != "" && sysFbqdm != null){
  						$("#FastPrint_fcybq").combobox('select',sysFbqdm);
  					}
  				}
  				
  			});
  		}
  //查询
  	function FastPrint(){
  		var date1 = $("#FastPrint_Date1").datebox("getValue");
  		var date2 = $("#FastPrint_Date2").datebox("getValue");
  		var fcydept = $("#FastPrint_Dept").combobox("getValue");
  		var fcybq = $("#FastPrint_fcybq").textbox("getValue");
  		var fprn = $("#FastPrint_Fprn").textbox("getValue");
  		var fname = $("#FastPrint_Name").textbox("getValue");
  		var fzydoc = $("#FastPrint_fzydoc").numberbox("getValue");
  		
  		$("#FastPrintGrid").datagrid({
  			url:ctx + "/Print/fastPrintQuery",
  			queryParams:{
  				"date1" : date1,
  				"date2" : date2,
  				"fcydept" : fcydept,
  				"fcybq" : fcybq,
  				"fprn" : fprn,
  				"fname" : fname,
  				"fzydoc" : fzydoc
  			}
  		});
  	}

  	//打开快速打印页面
  	function openRegister(index){
  		var rows = $("#FastPrintGrid").datagrid("getRows")[index];
  		var fcydate = new Date(rows.fcydate).format("yyyy-MM-dd");
  		var frydate = new Date(rows.frydate).format("yyyy-MM-dd");
  		var url = ctx + "/Print/?fprn="+rows.fprn+"&fzyid="+rows.fzyid+"&fcydate="+fcydate+"&frydate="+frydate+
  					"&fcydept="+encodeURI(encodeURI(rows.fcydept))+"&fcybs="+encodeURI(encodeURI(rows.fcybs))+"&fname="+encodeURI(encodeURI(rows.fname))+"&fidcard="+rows.fidcard
  					+"&location="+rows.location;
  		addTab("复印登记--直接打印", url,"", false);
  		/* var tabPanel = $('#tabs');
  		tabPanel.tabs('close',"打印登记查询"); */
  	}
